package o;

import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;
import huawei.widget.HwAlphaIndexerListView;
import huawei.widget.HwAlphaIndexerListView.a;
import huawei.widget.HwSortedTextListAdapter;

public class fps {
    private OnScrollListener ʼ = new OnScrollListener(this) {
        final /* synthetic */ fps ॱ;

        {
            this.ॱ = r1;
        }

        public void onScrollStateChanged(AbsListView absListView, int i) {
            switch (i) {
                case 0:
                    this.ॱ.ˎ = false;
                    this.ॱ.ˋ.ˋ();
                    return;
                case 2:
                    this.ॱ.ˎ = true;
                    this.ॱ.ˊ = this.ॱ.ˏ.getFirstVisiblePosition();
                    return;
                default:
                    return;
            }
        }

        public void onScroll(AbsListView absListView, int i, int i2, int i3) {
            this.ॱ.ˋ.invalidate();
            this.ॱ.ˋ.setOverLayInfo(this.ॱ.ˋ(this.ॱ.ॱ.getSectionForPosition(i)));
            if (this.ॱ.ˎ && Math.abs(i - this.ॱ.ˊ) > 2) {
                this.ॱ.ˋ.ˊ();
            }
        }
    };
    private int ˊ = 0;
    private HwAlphaIndexerListView ˋ;
    private boolean ˎ;
    private ListView ˏ;
    private HwSortedTextListAdapter ॱ;
    private a ᐝ = new a(this) {
        final /* synthetic */ fps ˊ;

        {
            this.ˊ = r1;
        }

        public void ˊ(String str, int i) {
            if (str != null) {
                String str2;
                String[] strArr = (String[]) this.ˊ.ॱ.getSections();
                int i2 = 0;
                while (i2 < strArr.length) {
                    if (this.ˊ.ˋ.ˏ(str, strArr[i2], i)) {
                        str2 = strArr[i2];
                        break;
                    }
                    i2++;
                }
                str2 = null;
                i2 = i;
                if (str2 != null) {
                    this.ˊ.ˋ.ˎ(str2);
                    i2 = this.ˊ.ॱ.getPositionForSection(i2);
                    if (i2 != -1) {
                        this.ˊ.ˏ.setSelection(i2);
                    }
                    int lastVisiblePosition = (this.ˊ.ˏ.getLastVisiblePosition() - this.ˊ.ˏ.getFirstVisiblePosition()) + 1;
                    if (i2 + lastVisiblePosition > this.ˊ.ˏ.getCount()) {
                        str2 = (String) this.ˊ.ॱ.getSectionNameForPosition(this.ˊ.ˏ.getCount() - lastVisiblePosition);
                    }
                    this.ˊ.ˋ.setOverLayInfo(i, str2);
                    return;
                }
                if (!this.ˊ.ˋ.ˎ(i)) {
                    this.ˊ.ˋ.ˎ(str);
                } else if (this.ˊ.ˋ.ˏ()) {
                    this.ˊ.ˏ.setSelection(this.ˊ.ˏ.getCount() - 1);
                } else {
                    this.ˊ.ˏ.setSelection(0);
                }
                this.ˊ.ˋ.setOverLayInfo(i, this.ˊ.ˋ(this.ˊ.ॱ.getSectionForPosition(this.ˊ.ˏ.getFirstVisiblePosition())));
            }
        }
    };

    public fps(ListView listView, HwAlphaIndexerListView hwAlphaIndexerListView) {
        this.ˏ = listView;
        this.ॱ = (HwSortedTextListAdapter) listView.getAdapter();
        this.ˋ = hwAlphaIndexerListView;
        this.ˋ.setListViewAttachTo(this.ˏ);
        this.ˋ.setOverLayInfo(ˋ(this.ॱ.getSectionForPosition(this.ˏ.getFirstVisiblePosition())));
    }

    private String ˋ(int i) {
        String str = "";
        if (this.ॱ.getSections().length <= i || i < 0) {
            return str;
        }
        return (String) this.ॱ.getSections()[i];
    }

    public void ˊ() {
        this.ˏ.setOnScrollListener(this.ʼ);
        this.ˋ.setOnItemClickListener(this.ᐝ);
    }
}
